<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

require_once dirname(__FILE__) . '/BaseDAO.php';

class DAOAdmin extends BaseDAO {

    /**
     * Constructeur de la classe DAOAdmin
     */
    public function __construct() {
        parent::__construct();
    }

    public function connectionAdmin(Admin $admin) {
        try {
            $requete = "SELECT count(*) FROM admin WHERE login='" . mysql_escape_string($admin->getLogin()) . "' AND password='" . mysql_escape_string($admin->getPassword()) . "'";

            $resultats = $this->connection->query($requete);
            $req = $resultats->fetch();

            if ($req[0] == 1) {
                echo "true";

                //header('Location: administration.php');
                //si connexion valide on cree une session
                session_start();
                $_SESSION['login'] = $admin->getLogin();
                //header('Location : administration.php');
                exit();
            } else {
                throw new Exception("Connexion impossible");
            }
        } catch (Exception $e) {
            throw new Exception("Problème lors de la connexion administrateur");
        }
    }

}

?>
